package com.gugee.tiktok.deploy.consumer.all.controller;

import com.gugee.common.thread.ScheduleTemplate;
import com.xiguaji.boot.toolkit.DateTimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;


@RestController
public class EndpointController {
    @Autowired
    ScheduleTemplate scheduleTemplate;

    @GetMapping("pools")
    public Map<String, String> getSchedule() {
        Map<String, String> hashMap = new LinkedHashMap<>();
        scheduleTemplate.getNameThreadMap().entrySet().stream().forEach(entry -> {
            hashMap.put(entry.getKey(), "activity:" + entry.getValue().getActiveCount() +
                    " poolSize:" + entry.getValue().getPoolSize() +
                    " corePoolSize:" + entry.getValue().getCorePoolSize() +
                    " TaskCount:" +entry.getValue().getTaskCount()+
                    " CompletedTaskCount:" +entry.getValue().getCompletedTaskCount()

            );
        });
        scheduleTemplate.getNameForkJoinPool().entrySet().stream().forEach(entry -> {
            hashMap.put(entry.getKey(),
                    "activity:" + entry.getValue().getActiveThreadCount() +
                            " running:" + entry.getValue().getRunningThreadCount() +
                            " submit:" + entry.getValue().getQueuedSubmissionCount() +
                            " queued:" + entry.getValue().getQueuedTaskCount() +
                            " stealCount:"+entry.getValue().getStealCount() +
                            " poolSize:" + entry.getValue().getPoolSize());
        });
        hashMap.put("new Date:", new Date().toString());
        hashMap.put("new DateTime:", String.valueOf(new Date().getTime()));
        hashMap.put("currentTimeSecond:", String.valueOf(DateTimeUtils.currentTimeSecond()));
        hashMap.put("SystemCurrentTimeSecond:", String.valueOf(System.currentTimeMillis()));
        hashMap.put("LocalDateTime.now():", LocalDateTime.now().toString());
        return hashMap;
    }
}
